package io.framework.modules.app.controller;

import io.framework.common.annotation.LogOperation;
import io.framework.common.constant.Constant;
import io.framework.common.exception.ErrorCode;
import io.framework.common.exception.RenException;
import io.framework.common.page.PageData;
import io.framework.common.utils.Result;
import io.framework.common.validator.AssertUtils;
import io.framework.common.validator.ValidatorUtils;
import io.framework.common.validator.group.AddGroup;
import io.framework.common.validator.group.DefaultGroup;
import io.framework.modules.air.dto.AirDTO;
import io.framework.modules.air.service.AirService;
import io.framework.modules.hpinfo.dto.*;
import io.framework.modules.hpinfo.service.*;
import io.framework.modules.pollutionsource.dto.*;
import io.framework.modules.pollutionsource.service.TBasPollutionService;
import io.framework.modules.pollutionsource.service.TBasPollutionlabeldirService;
import io.framework.modules.security.dto.LoginDTO;
import io.framework.modules.security.password.PasswordUtils;
import io.framework.modules.security.service.SysUserTokenService;
import io.framework.modules.station.dto.StationDTO;
import io.framework.modules.station.service.StationService;
import io.framework.modules.sys.dto.*;
import io.framework.modules.sys.entity.StatuteEntity;
import io.framework.modules.sys.enums.UserStatusEnum;
import io.framework.modules.sys.service.FavoritesService;
import io.framework.modules.sys.service.StatuteService;
import io.framework.modules.sys.service.SysAddressListService;
import io.framework.modules.sys.service.SysUserService;
import io.framework.modules.water.dto.WaterMonitorDTO;
import io.framework.modules.water.service.WaterMonitorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import java.util.*;

@RestController
@Api(tags = "APP接口")
@SuppressWarnings("all")
public class AppApiController {


    @Autowired
    private WaterMonitorService waterMonitorService;
    /**
     * 环评
     */
    @Autowired
    private VTHpglProjectinfoService vTHpglProjectinfoService;
    /**
     * 污染源监控基本信息 一般污染源
     */
    @Autowired
    private TBasPollutionService basPollutionService;
    /**
     * 污染源标签年份表名录 （重点排污单位，环统单位）
     */
    @Autowired
    private TBasPollutionlabeldirService basPollutionlabeldirService;
    /**
     * 环境影响评价管理-环评建设单位信息
     */
    @Autowired
    private VTHpglJsdwinfoService vTHpglJsdwinfoService;
    /**
     * 环境影响评价管理-环评审批保护区及风景区情况
     */
    @Autowired
    private VTHpglHpspbhqjfjqService vTHpglHpspbhqjfjqService;
    /**
     * 环境影响评价管理-环评审批污染物排放量信息
     */
    @Autowired
    private VTHpglHpspwrwpflService vTHpglHpspwrwpflService;
    /**
     * 用户信息
     */
    @Autowired
    private SysUserService sysUserService;

    /**
     * 收藏夹
     */
    @Autowired
    private FavoritesService favoritesService;

    /**
     * 法律法规
     *
     */
    @Autowired
    private StatuteService statuteService;

    /**
     * token
     */
    @Autowired
    private SysUserTokenService sysUserTokenService;
    /**
     * 通讯录
     */
    @Autowired
    private SysAddressListService sysAddressListService;
    /**
     * 审批附件
     */
    @Autowired
    private VTHpglSpfjinfoService tHpglSpfjinfoService;
    /**
     * 一般污染源
     */
    @Autowired
    private TBasPollutionService tBasPollutionService;
    /**
     * 重点污染企业
     */
    @Autowired
    private TBasPollutionlabeldirService tBasPollutionlabeldirService;
    /**
     * 站点信息
     */
    @Autowired
    private StationService stationService;
    /**
     * 空气信息
     */
    @Autowired
    private AirService airService;


    @GetMapping("app/hglProjectinfo/all")
    @ApiOperation("app-环评 -- 环评显示所有建设项目坐标信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectXmmc", value = "项目名称", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "pffsName", value = "排放方式   直接排放、间接排放、不排放    （多个以英文逗号”,“隔开）", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "ifXkz", value = "是否有许可证  是  否 ", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "hpspbm", value = "环评审批机构", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "regionName", value = "区域   天涯区  吉阳区 海棠区 崖州区   （多个以英文逗号”,“隔开）", paramType = "query", dataType = "String"),
    })
    public Result<List<HpglProjectGoordInfoDTO>> getCoordList(@ApiIgnore @RequestParam Map<String, Object> params) {

        List<HpglProjectGoordInfoDTO> list = vTHpglProjectinfoService.getCoordList(params);

        return new Result<List<HpglProjectGoordInfoDTO>>().ok(list);
    }

    @GetMapping("app/hglProjectinfo/list")
    @ApiOperation("app-环评 -- 环评数据列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectXmmc", value = "项目名称", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "pffsName", value = "排放方式   直接排放、间接排放、不排放    （多个以英文逗号”,“隔开）", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "ifXkz", value = "是否有许可证  是  否 ", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "ifWry", value = "是否有污染源  是  否 ", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "hpspbm", value = "环评审批部门", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "regionName", value = "区域   天涯区  吉阳区 海棠区 崖州区   （多个以英文逗号”,“隔开）", paramType = "query", dataType = "String"),
    })
    public Result<List<VTHpglProjectinfoDTO>> lists(@ApiIgnore @RequestParam Map<String, Object> params) {

        List<VTHpglProjectinfoDTO> page = vTHpglProjectinfoService.lists(params);

        return new Result<List<VTHpglProjectinfoDTO>>().ok(page);
    }

    @GetMapping("app/hglProjectinfo/info")
    @ApiOperation("app-环评 -- 查询建设项目 -- 详细信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "建设项目主键", paramType = "query", required = true, dataType = "String"),
    })
    public Result<VTHpglProjectinfoDTO> getHglProjectinfo(String id) {

        VTHpglProjectinfoDTO data = vTHpglProjectinfoService.selectById(id);

        return new Result<VTHpglProjectinfoDTO>().ok(data);
    }

    @GetMapping("app/hpinfo/vthpglprojectinfo/getSpjgList")
    @ApiOperation("app-环评 -- 所有审批机构")
    public Result<List<Map<String, Object>>> getSpjgList() {

        List<Map<String, Object>> data = vTHpglProjectinfoService.getSpjgList();

        return new Result<List<Map<String, Object>>>().ok(data);
    }

    @GetMapping("app/hpinfo/vthpgljsdwinfo/getJsdwInfoByProjectId")
    @ApiOperation("app-根据建设项目ID-查询建设单位信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "建设项目主键", paramType = "query", required = true, dataType = "String"),
    })
    public Result<VTHpglJsdwinfoDTO> getJsdwInfoByProjectId(String id) {

        VTHpglJsdwinfoDTO data = vTHpglJsdwinfoService.getProjectInfoByProjectId(id);

        return new Result<VTHpglJsdwinfoDTO>().ok(data);
    }

    @GetMapping("app/hpinfo/vthpglhpspbhqjfjq/getHpspBhqInfoByProjectId")
    @ApiOperation("app-根据建设项目ID查询-环评审批保护区及风景区情况")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "建设项目主键", paramType = "query", required = true, dataType = "String"),
    })
    public Result<VTHpglHpspbhqjfjqDTO> getHpspBhqInfoByProjectId(String id) {

        VTHpglHpspbhqjfjqDTO data = vTHpglHpspbhqjfjqService.getProjectInfoByProjectId(id);

        return new Result<VTHpglHpspbhqjfjqDTO>().ok(data);
    }

    @GetMapping("app/hpinfo/vthpglhpspwrwpfl/getHpspPfwInfoByProjectId")
    @ApiOperation("app-根据建设项目ID查询-环评审批污染物排放量信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "建设项目主键", paramType = "query", dataType = "String", required = true),
    })
    public Result<VTHpglHpspwrwpflDTO> getHpspPfwInfoByProjectId(String id) {

        VTHpglHpspwrwpflDTO data = vTHpglHpspwrwpflService.getProjectInfoByProjectId(id);

        return new Result<VTHpglHpspwrwpflDTO>().ok(data);
    }

    @GetMapping("app/pollution/all")
    @ApiOperation("app-污染源--坐标信息列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "regionName", value = "区域  （多个以英文逗号“,”隔开）", paramType = "query", required = false, dataType = "string"),
            @ApiImplicitParam(name = "attentionDegreeName", value = "关注程度  县控  市控  省控  国控 其他   （多个以英文逗号“,”隔开）", paramType = "query", required = false, dataType = "string"),
            @ApiImplicitParam(name = "wryName", value = "污染源名称", paramType = "query", required = false, dataType = "string"),
    })
    public Result<PollutionListDTO> pollutionAll(@ApiIgnore @RequestParam Map<String, Object> params) {
        PollutionListDTO pollutionListDTO = new PollutionListDTO();

        List<PollutionGoordInfoDTO> pollutionGoordInfoDTOS = basPollutionService.getCoordList(params);
        List<PollutionlabeldirGoordInfoDTO> pollutionlabeldirGoordInfoDTOS = basPollutionlabeldirService.getCoordList(params);

        pollutionListDTO.setGeneralWRYGoordList(pollutionGoordInfoDTOS);
        pollutionListDTO.setAttentionWRYGoordList(pollutionlabeldirGoordInfoDTOS);

        return new Result<PollutionListDTO>().ok(pollutionListDTO);
    }

    @GetMapping("app/generalWRYInfo/info")
    @ApiOperation("app- 一般污染源 -- 详细信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "pkPollutionid  主键", paramType = "query", dataType = "String"),
    })
    public Result<TBasPollutionDTO> getGeneralWRYInfo(String id) {

        TBasPollutionDTO data = basPollutionService.selectById(id);

        return new Result<TBasPollutionDTO>().ok(data);
    }

    @GetMapping("app/attentionWRYInfo/info")
    @ApiOperation("app-重点污染企业 -- 详细信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "pkDirid  主键", paramType = "query", dataType = "String"),
    })
    public Result<TBasPollutionlabeldirDTO> getattentionWRYInfo(String id) {

        TBasPollutionlabeldirDTO data = basPollutionlabeldirService.selectById(id);

        return new Result<TBasPollutionlabeldirDTO>().ok(data);
    }

    @PostMapping("app/user/login")
    @ApiOperation(value = "app-登录")
    public Result login(HttpServletRequest request, @RequestBody LoginDTO login) {
        //效验数据
        ValidatorUtils.validateEntity(login);
        //用户信息
        SysUserDTO user = sysUserService.getByUsername(login.getUsername());
        //用户不存在
        if (user == null) {
            throw new RenException(ErrorCode.ACCOUNT_PASSWORD_ERROR);
        }
        //密码错误
        if (!PasswordUtils.matches(login.getPassword(), user.getPassword())) {
            throw new RenException(ErrorCode.ACCOUNT_PASSWORD_ERROR);
        }
        //账号停用
        if (user.getStatus() == UserStatusEnum.DISABLE.value()) {
            throw new RenException(ErrorCode.ACCOUNT_DISABLE);
        }
        return sysUserTokenService.createToken(user.getId(),"0");
    }

    @PostMapping("app/user/loginss")
    @ApiOperation(value = "app-手势登录")
    public Result loginss(HttpServletRequest request, @RequestBody LoginDTO login) {
        //效验数据
      //  ValidatorUtils.validateEntity(login);
        //用户信息
        SysUserDTO user = sysUserService.getByUsername(login.getUsername());
        //用户不存在
        if (user == null) {
            throw new RenException(ErrorCode.ACCOUNT_PASSWORD_ERROR);
        }
        //密码错误
//        if (!PasswordUtils.matches(login.getPassword(), user.getPasswordss())) {
//            throw new RenException(ErrorCode.ACCOUNT_PASSWORD_ERROR);
//        }
        if (!login.getPassword().equals(user.getPasswordss()) ) {
            throw new RenException("手势密码错误！");
        }


        //账号停用
        if (user.getStatus() == UserStatusEnum.DISABLE.value()) {
            throw new RenException(ErrorCode.ACCOUNT_DISABLE);
        }
        return sysUserTokenService.createToken(user.getId(),"0");
    }


    @PutMapping("app/user/updatePasswordss")
    @ApiOperation("app-修改手势密码")
    public Result updatePasswordss(@RequestBody PasswordDTO dto, HttpServletRequest request) {

        //效验数据
       // ValidatorUtils.validateEntity(dto);
        String token = request.getHeader(Constant.TOKEN_HEADER);

        AssertUtils.isBlank(token, ErrorCode.TOKEN_INVALID);

        SysUserDTO user = sysUserTokenService.getUserInfobytoken(token);
        if (user == null) {
            return new Result().error(ErrorCode.ACCOUNT_NOT_EXIST);
        }
//        //原密码不正确
//        if (!PasswordUtils.matches(dto.getPassword(), user.getPassword())) {
//            return new Result().error(ErrorCode.PASSWORD_ERROR);
//        }
        sysUserService.updatePasswordss(user.getId(), dto.getNewPassword());
        return new Result();
    }




    @PutMapping("app/user/updatePassword")
    @ApiOperation("app-修改密码")
    public Result password(@RequestBody PasswordDTO dto, HttpServletRequest request) {

        //效验数据
        ValidatorUtils.validateEntity(dto);
        String token = request.getHeader(Constant.TOKEN_HEADER);

        AssertUtils.isBlank(token, ErrorCode.TOKEN_INVALID);

        SysUserDTO user = sysUserTokenService.getUserInfobytoken(token);
        if (user == null) {
            return new Result().error(ErrorCode.ACCOUNT_NOT_EXIST);
        }
        //原密码不正确
        if (!PasswordUtils.matches(dto.getPassword(), user.getPassword())) {
            return new Result().error(ErrorCode.PASSWORD_ERROR);
        }
        sysUserService.updatePassword(user.getId(), dto.getNewPassword());
        return new Result();
    }

    @GetMapping("app/addressList/list")
    @ApiOperation("app-通讯录--所有通信录信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "username", value = "姓名", paramType = "query", required = false, dataType = "string"),
    })
    public Result<List<SysAddressListDTO>> addressList(@ApiIgnore @RequestParam Map<String, Object> params) {

        List<SysAddressListDTO> list = sysAddressListService.lists(params);

        return new Result<List<SysAddressListDTO>>().ok(list);
    }

    @GetMapping("app/user/info")
    @ApiOperation("app-获取用户详细信息")
    public Result<SysUserDTO> getUserInfo(@ApiIgnore @RequestParam Map<String, Object> params, HttpServletRequest request) {

        String token = request.getHeader(Constant.TOKEN_HEADER);
        AssertUtils.isBlank(token, ErrorCode.TOKEN_INVALID);

        SysUserDTO userDTO = sysUserTokenService.getUserInfobytoken(token);
        return new Result<SysUserDTO>().ok(userDTO);
    }

    @GetMapping("app/hpinfo/thpglspfjinfo/getSpfjInfoByProjectId")
    @ApiOperation("根据建设项目ID查询-环评附件信息列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "建设项目主键", paramType = "query", dataType = "String", required = true),
    })
    public Result<List<VTHpglSpfjinfoDTO>> getProjectInfoByProjectId(String id) {

        List<VTHpglSpfjinfoDTO> data = tHpglSpfjinfoService.getSpfjInfoByProjectId(id);

        return new Result<List<VTHpglSpfjinfoDTO>>().ok(data);
    }


    @GetMapping("app/pollutionsource/tbaspollution/page")
    @ApiOperation("一般污染源信息--分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = Constant.PAGE, value = "当前页码，从1开始", paramType = "query", required = true, dataType = "int"),
            @ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query", required = true, dataType = "int"),
            @ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = Constant.ORDER, value = "排序方式，可选值(asc、desc)", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "keyName", value = "关键字", paramType = "query", dataType = "String"),
    })
    public Result<PageData<TBasPollutionDTO>> tbaspollutionpage(@ApiIgnore @RequestParam Map<String, Object> params) {

        PageData<TBasPollutionDTO> page = tBasPollutionService.pages(params);

        return new Result<PageData<TBasPollutionDTO>>().ok(page);
    }

    @GetMapping("app/pollutionsource/tbaspollutionlabeldir/page")
    @ApiOperation("重点污染源信息--分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = Constant.PAGE, value = "当前页码，从1开始", paramType = "query", required = true, dataType = "int"),
            @ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query", required = true, dataType = "int"),
            @ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = Constant.ORDER, value = "排序方式，可选值(asc、desc)", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "keyName", value = "关键字", paramType = "query", dataType = "String"),
    })
    public Result<PageData<TBasPollutionlabeldirDTO>> tbaspollutionlabeldirpage(@ApiIgnore @RequestParam Map<String, Object> params) {

        PageData<TBasPollutionlabeldirDTO> page = tBasPollutionlabeldirService.pages(params);

        return new Result<PageData<TBasPollutionlabeldirDTO>>().ok(page);
    }

    @GetMapping("app/hpinfo/vthpglprojectinfo/page")
    @ApiOperation("环评建设单位--分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = Constant.PAGE, value = "当前页码，从1开始", paramType = "query", required = true, dataType = "int"),
            @ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query", required = true, dataType = "int"),
            @ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = Constant.ORDER, value = "排序方式，可选值(asc、desc)", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "projectXmmc", value = "项目名称", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "pffsName", value = "排放方式   直接排放、间接排放、不排放    （多个以英文逗号”,“隔开）", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "ifXkz", value = "是否有许可证  是  否 ", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "ifWry", value = "是否有污染源  是  否 ", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "hpspbm", value = "环评审批部门", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "regionName", value = "区域   天涯区  吉阳区 海棠区 崖州区   （多个以英文逗号”,“隔开）", paramType = "query", dataType = "String"),
    })
    public Result<PageData<VTHpglProjectinfoDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params) {

        PageData<VTHpglProjectinfoDTO> page = vTHpglProjectinfoService.pages(params);

        return new Result<PageData<VTHpglProjectinfoDTO>>().ok(page);
    }

    @GetMapping("app/station/getStationInfoByParams")
    @ApiOperation("获取站点信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "站点名称", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "type", value = " 1-空气 2-水 3-土壤 4-噪声", paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "control", value = "空气：1-国控 2-全市 3-省控  水： 1-地表水 2-城镇内河 3-重点治理城镇内河 4-引用水源地  噪声 ：1-道路交通噪声 2-区域环境噪声 3-功能区噪声", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "xmin", value = "最小经度", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "xmax", value = "最大经度", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "ymin", value = "最小纬度", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "ymax", value = "最大纬度", paramType = "query", dataType = "String"),
    })
    public Result<List<StationDTO>> getStationInfoByParams(@ApiIgnore @RequestParam Map<String, Object> params) {

        List<StationDTO> list = stationService.getStationInfoByParams(params);
        list.forEach(v -> {
            if (v.getType() == 1) {
                //空气
                Map<String, Object> map = new HashMap<>();
                map.put("stationId", v.getId());
                map.put("type", v.getType());
                AirDTO airDTO = airService.getAirDTOIOnfoByParam(map);
                if (airDTO != null) {
                    v.setLevel(airDTO.getLevel());
                    v.setClassify(airDTO.getClassify());
                }
            }
        });
        return new Result<List<StationDTO>>().ok(list);
    }

    @GetMapping("app/air/sort")
    @ApiOperation("空气质量排名")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "1-国控  2-全市", paramType = "query", required = true),
    })
    public Result<List<Map<String, Object>>> getAirStationInfoSort(@ApiIgnore @RequestParam Map<String, Object> params) {
        List<Map<String, Object>> airDTOList = airService.getAirStationInfoSort(params);

        return new Result<List<Map<String, Object>>>().ok(airDTOList);
    }

    @GetMapping("app/air/info")
    @ApiOperation("查询空气站点实时数据信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "stationId", value = "站点id", paramType = "query", required = true),
    })
    public Result<AirDTO> getAirStationInfoById(@ApiIgnore @RequestParam Map<String, Object> params) {
        AirDTO airDTO = airService.getAirDTOIOnfoByParams(params);

        return new Result<AirDTO>().ok(airDTO);
    }

    @GetMapping("app/air/page")
    @ApiOperation("分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = Constant.PAGE, value = "当前页码，从1开始", paramType = "query", required = true, dataType = "int"),
            @ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query", required = true, dataType = "int"),
            @ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = Constant.ORDER, value = "排序方式，可选值(asc、desc)", paramType = "query", dataType = "String")
    })
    public Result<PageData<AirDTO>> airPage(@ApiIgnore @RequestParam Map<String, Object> params) {

        PageData<AirDTO> page = airService.page(params);

        return new Result<PageData<AirDTO>>().ok(page);
    }


    @GetMapping("app/air/info/aqiHistoryChange")
    @ApiOperation("站点AQI历史变化对比图")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "1-国控 2-全市", paramType = "query", dataType = "int",required = true),
            @ApiImplicitParam(name = "stationId", value = "站点ID", paramType = "query", dataType = "array"),
            @ApiImplicitParam(name = "startDate", value = "开始时间 2020-5-20", paramType = "query", dataType = "String",required = true),
            @ApiImplicitParam(name = "endDate", value = "结束时间 2020-5-21", paramType = "query", dataType = "String",required = true),
    })
    public Result<List<Map<String,Object>>> aqiHistoryChange(@ApiIgnore @RequestParam Map<String, Object> params) {
        List<Map<String, Object>> map = airService.aqiHistoryChange(params);
        return new Result<List<Map<String, Object>>>().ok(map);

    /*
    @GetMapping("app/air/info")
    @ApiOperation("查询空气站点实时数据信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "addrss", value = "请求接口", paramType = "query", required = true),
    })
    public Result<Map<String,Object>> getAirStationInfoById(@ApiIgnore @RequestParam Map<String, Object> params) {

        Map<String,Object> map  = AirMonitorUtil.getAirMinitorInfo(params);

        return new Result<Map<String,Object>>().ok(map);
    }*/
    }



    @PostMapping("app/favorites/save")
    @ApiOperation("保存")
    @LogOperation("添加收藏夹信息")
   // @RequiresPermissions("sys:user:save")
    public Result save(FavoritesDTO dto) {

        //效验数据
       // ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);

//        FavoritesDTO user = favoritesService.getByUsername(dto.getUsername());
//        if (user != null) {
//            return new Result().error(ErrorCode.USERNAME_ALREADY_USERD);
//        }
        favoritesService.save(dto);

        return new Result();
    }


    @GetMapping("app/favorites/pagewry")
    @ApiOperation("分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = Constant.PAGE, value = "当前页码，从1开始", paramType = "query", required = true, dataType = "int"),
            @ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query", required = true, dataType = "int"),
            @ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = Constant.ORDER, value = "排序方式，可选值(asc、desc)", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "wryName", value = "污染源名称", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "userId", value = "用户ID", paramType = "query", dataType = "String"),
    })
    public Result<PageData<FavoritesDTO>> pagewry(@ApiIgnore @RequestParam Map<String, Object> params) {
        PageData<FavoritesDTO> page = favoritesService.page(params);
        return new Result<PageData<FavoritesDTO>>().ok(page);
    }

    @GetMapping("app/water/info/getStationNameList")
    @ApiOperation("站点污染物浓度月度变化 -- 获取所有断面")
    public Result<List<Map<String, Object>>> getStationName() {

        List<Map<String, Object>> mapList = waterMonitorService.getStationName();

        return new Result<List<Map<String, Object>>>().ok(mapList);
    }

    @GetMapping("app/water/info/ndMonthChange")
    @ApiOperation("站点污染物浓度月度变化")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dateType", value = "1-年度 2-季度 3-月份", paramType = "query", dataType = "String", required = true),
            @ApiImplicitParam(name = "date", value = "年 2020、季 2020-Q1 2020-Q2 2020-Q3 2020-Q4、月 2020-04", paramType = "query", dataType = "String", required = true),
            @ApiImplicitParam(name = "stationName", value = "断面名称", paramType = "query", dataType = "String", required = true),
            @ApiImplicitParam(name = "factor", value = "因子 PH、YD-盐度、DOO2-溶解氧、COD-化学需氧量、H2PO4-活性磷酸盐、OIL-石油类、Nmin-无机氮、K2MnO4-高锰酸钾、NH3-氨氮、TP-总磷、TN-总氮", paramType = "query", dataType = "String", required = true),
    })
    public Result<List<Map<String, Object>>> ndMonthChange(@ApiIgnore @RequestParam Map<String, Object> params) {

        List<Map<String, Object>> mapList = waterMonitorService.getWaterndMonthChange(params);

        return new Result<List<Map<String, Object>>>().ok(mapList);
    }


    @GetMapping("app/statute/pageStatute")
    @ApiOperation("分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = Constant.PAGE, value = "当前页码，从1开始", paramType = "query", required = true, dataType = "int"),
            @ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query", required = true, dataType = "int"),
            @ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = Constant.ORDER, value = "排序方式，可选值(asc、desc)", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "bt", value = "标题", paramType = "query", dataType = "String"),
    })
    public Result<PageData<StatuteDTO>> pageStatute(@ApiIgnore @RequestParam Map<String, Object> params) {
        PageData<StatuteDTO> page = statuteService.page(params);
        return new Result<PageData<StatuteDTO>>().ok(page);
    }


    @GetMapping("app/statute/statuteInfo")
    @ApiOperation("app-重点污染企业 -- 详细信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "pkDirid  主键", paramType = "query", dataType = "String"),
    })
    public Result<StatuteEntity> statuteInfo(String id) {

        StatuteEntity data = statuteService.selectById(id);

        return new Result<StatuteEntity>().ok(data);
    }



    @GetMapping("app/water/watermonitor/pageList")
    @ApiOperation("分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = Constant.PAGE, value = "当前页码，从1开始", paramType = "query", required = true, dataType = "int"),
            @ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query", required = true, dataType = "int"),
            @ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = Constant.ORDER, value = "排序方式，可选值(asc、desc)", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "time", value = "监测月份（例：2020-01）", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "type", value = "type：1-海水河流型 2-湖库型 3-淡水河流型", paramType = "query", dataType = "int")
    })
//    @RequiresPermissions("water:watermonitor:page")
    public Result<PageData<WaterMonitorDTO>> pageList(@ApiIgnore @RequestParam Map<String, Object> params) {
        if (!params.containsKey(Constant.PAGE) || !params.containsKey(Constant.LIMIT)) {
            return new Result<PageData<WaterMonitorDTO>>().error("参数错误");
        }
        PageData<WaterMonitorDTO> page = waterMonitorService.pageList(params);
        return new Result<PageData<WaterMonitorDTO>>().ok(page);
    }



    @GetMapping("app/hpinfo/vthpglprojectinfo/getHpglProjectCount")
    @ApiOperation("根据环评日期统计环评建设项目")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "year", value = "年份 -例： 2020", paramType = "query", required = true, dataType = "int"),
    })
    public Result<List<Map<String,Object>>> getHpglProjectCount(@ApiIgnore @RequestParam Map<String, Object> params){
        List<Map<String,Object>> list = vTHpglProjectinfoService.getHpglProjectCount(params);

        return new Result<List<Map<String,Object>>>().ok(list);
    }


    @GetMapping("app/hpinfo/vthpglprojectinfo/getHpglProjectTableCountApp")
    @ApiOperation("环评建设项目表格显示  个报告书、报告表 个数")
    public Result<List<Map<String,Object>>> getHpglProjectTableCount(@ApiIgnore @RequestParam Map<String, Object> params){
        List<Map<String,Object>> list = vTHpglProjectinfoService.getHpglProjectTableCountApp(params);
        boolean a=false;
        boolean b=false;
        boolean c=false;
        boolean d=false;
        for ( Map<String,Object> map :list){
            if (map.get("name").equals("环保备案")){
                 a =true;
            }
            if (map.get("name").equals("环境影响报告书")){
                b =true;
            }
            if (map.get("name").equals("环境影响报告表")){
                c =true;
            }
            if (map.get("name").equals("环境影响登记表")){
                d =true;
            }
        }
        Map<String, Object> map1=new HashMap();
        Map<String, Object> map2=new HashMap();
        Map<String, Object> map3=new HashMap();
        Map<String, Object> map4=new HashMap();
        if(!a){
            map1.put("name","环保备案");
            map1.put("value","0");
            list.add(map1);
        }
        if(!b){
            map2.put("name","环境影响报告书");
            map2.put("value","0");
            list.add(map2);
        }
        if(!c){
            map3.put("name","环境影响报告表");
            map3.put("value","0");
            list.add(map3);
        }
        if(!d){
            map4.put("name","环境影响登记表");
            map4.put("value","0");
            list.add(map4);
        }

        return new Result<List<Map<String,Object>>>().ok(list);
    }



    @GetMapping("app/hpinfo/vthpglprojectinfo/getHbtzl")
    @ApiOperation("环保投资率")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "startDate", value = "2020-01", paramType = "query", required = true, dataType = "String"),
            @ApiImplicitParam(name = "endDate", value = "2020-02", paramType = "query", required = true, dataType = "String")
    })
    public Result<Map<String,Object>> getHbtzl(@ApiIgnore @RequestParam Map<String, Object> params){
        Map<String,Object> map1 =new HashMap<>();
        Map<String,Object> map = vTHpglProjectinfoService.getHbtzl(params);
         if(map!=null){
             return  new Result<Map<String,Object>>().ok(map);
        }else {
             map1.put("SJZTZ",0);
             map1.put("SJHBZTZ",0);
         }
        return  new Result<Map<String,Object>>().ok(map1);
    }


    @GetMapping("app/air/info/aqiHistoryPm")
    @ApiOperation("站点AQI历史变化对比图")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "1-国控 2-全市", paramType = "query", dataType = "int",required = true),
            @ApiImplicitParam(name = "startDate", value = "开始时间 2020-5-20", paramType = "query", dataType = "String",required = true),
            @ApiImplicitParam(name = "endDate", value = "结束时间 2020-5-21", paramType = "query", dataType = "String",required = true),
    })
    public Result<List<Map<String,Object>>> aqiHistoryPm(@ApiIgnore @RequestParam Map<String, Object> params) {

        List<Map<String, Object>> map = airService.aqiHistoryPm(params);

        return new Result<List<Map<String, Object>>>().ok(map);

    }

}
